const connection = require('../app/database')

class PermissionService {
  // 检查权限方法：
  // 当前登录用户的id和该用户发表的动态id能对应上
  async checkPermission(...payload) {

    // 1.获取请求参数
    const [tableName, recordId, id] = payload

    // 2.定义预处理语句
    const statement = `SELECT * FROM ${tableName} WHERE id = ? AND user_id = ?;`

    // 3.执行sql语句
    let [res, fields] = await connection.execute(statement, [recordId, id])
    return !!res.length
  }
}

module.exports = new PermissionService()